﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace Aoxuelf.MDSTool.Utils
{
    /// <summary>
    /// 资源管理器辅助类
    /// </summary>
    public static class ExplorerHelper
    {
        /// <summary>
        /// 打开指定文件或者文件夹所在的目录。
        /// </summary>
        /// <param name="path">文件或者文件夹路径</param>
        /// <param name="ignoreException">true表示忽略异常，否则false</param>
        public static void OpenFolder(string path, bool ignoreException)
        {
            Action action = () => { Process.Start("explorer.exe", string.Format("/select, \"{0}\"", path)); };
            if (ignoreException)
            {
                try
                {
                    action();
                }
                catch
                { }
            }
            else
            {
                SafeGuard.NotArgNull(path, "path");
                action();
            }
        }

        /// <summary>
        /// 打开指定文件或者文件夹所在的目录，如果出现异常则忽略。
        /// </summary>
        /// <param name="path">文件或者文件夹路径</param>
        public static void OpenFolder(string path)
        {
            OpenFolder(path, true);
        }

        /// <summary>
        /// 打开指定的文件
        /// </summary>
        /// <param name="path">文件路径</param>
        public static void OpenFile(string path)
        {
            try
            {
                Process p = new Process();
                p.StartInfo.FileName = "cmd.exe";
                p.StartInfo.Arguments = path;
                p.StartInfo.CreateNoWindow = true;
                p.StartInfo.UseShellExecute = false;
                p.Start();
            }
            catch
            {
            }
        }
    }
}
